<?php
/**
 * @author Voislav Jovanovic <voislavj@gmail.com>
 * main entry point for the framework
 */

class Controller {

	private $_view;
	
	public $autoRender = true;
	
	public function __construct() {
		$this->_view = new View();
	}
	
	public function loadModel($name) {
		$filename = class2file($name);
		$path = DIR_ROOT . "/app/models/$filename.php";
		if(file_exists($path)) {
			$this->$name = new $name;
		}else{
			throw new Exception("Model not found ($name).");
		}
	}

	public function render($action=null) {
		if(!$action) {
			$action = $this->_dispatcher->uri->action;
		}
		
		return $this->_view->render(class2file($this->_dispatcher->uri->controller) . "/$action");
	}
	
	public function set($name, $value) {
		$this->_view->set($name, $value);
	}
}

?>